Skip to content

C#: Fix the cs/path-combine code quality issues in the extractor.#21996

Merged
michaelnebel merged 3 commits into
github:mainfrom
michaelnebel:csharp/fixpathcombineissues
Jun 19, 2026
Merged

C#: Fix the cs/path-combine code quality issues in the extractor.#21996
michaelnebel merged 3 commits into
github:mainfrom
michaelnebel:csharp/fixpathcombineissues

Conversation

@michaelnebel

@michaelnebel michaelnebel commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Note, that the reason why Path.Combine is discouraged is because it is considered "vulnerable" to path injection attacks. Arguments prior to an argument with a rooted path are dropped. For that reason Path.Join is preferred over Path.Combine (as Path.Join doesn't drop any arguments). However, when replacing the uses of Path.Combine with Path.Join we need to re-write the cases where we actually rely on the "dropping" semantics of Path.Combine - but then it will also be more obvious that we are not accidentally dropping any arguments.

DCA looks good.

@github-actions github-actions Bot added the C# label Jun 17, 2026
@michaelnebel michaelnebel changed the title C#: Fix the cs/path-combine code quality issues in the extractor. C#: Fix the cs/path-combine code quality issues in the extractor. Jun 17, 2026
@michaelnebel michaelnebel force-pushed the csharp/fixpathcombineissues branch 2 times, most recently from 16e853c to 3364c20 Compare June 18, 2026 06:30
@michaelnebel michaelnebel added the no-change-note-required This PR does not need a change note label Jun 18, 2026
@michaelnebel michaelnebel requested a review from hvitved June 18, 2026 09:07
@michaelnebel michaelnebel marked this pull request as ready for review June 18, 2026 09:07
@michaelnebel michaelnebel requested a review from a team as a code owner June 18, 2026 09:07
Copilot AI review requested due to automatic review settings June 18, 2026 09:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 24/24 changed files
  • Comments generated: 1

}

return Path.GetFullPath(Path.Combine(projDir?.FullName ?? string.Empty, Path.DirectorySeparatorChar == '/' ? file.Replace("\\", "/") : file));
return Path.GetFullPath(Path.Join(projDir?.FullName ?? string.Empty, Path.DirectorySeparatorChar == '/' ? file.Replace("\\", "/") : file));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into what can happen in this particular case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point as the .csproj files can contain both relative and absolute paths.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the same reason, I have also looked through all other cases and tried to decide when we actually "want" to support the dropping semantics.

@michaelnebel michaelnebel marked this pull request as draft June 18, 2026 10:59
@michaelnebel michaelnebel force-pushed the csharp/fixpathcombineissues branch from 27c1900 to 03b525b Compare June 19, 2026 08:23
@michaelnebel michaelnebel marked this pull request as ready for review June 19, 2026 13:47
@michaelnebel michaelnebel requested review from a team as code owners June 19, 2026 13:47
@michaelnebel michaelnebel merged commit a076ffc into github:main Jun 19, 2026
17 checks passed
@michaelnebel michaelnebel deleted the csharp/fixpathcombineissues branch June 19, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants